jQuery(document).ready(function($) {
   $("#jobseekerloginform").jobUtil("setCaptcha", {
      captchaurl: showcaptchaurl
   });

   $.metadata.setType("attr", "validate"); 
   $("#jobseekerloginform").validate({
      submitHandler: function(form) {
         $(form).ajaxSubmit({
           dataType: "json", 
           beforeSubmit: function(data, form, options) { 
               if(!showLoading("jobseekerloginform"))
                  return false;
               $("#regmsg").hide(); 
            },
            success: function(data) {
              try {
                 var retmsg = data; 
                 if(retmsg.error) {
                     $("#regmsg").jobUtil("showError", retmsg.error);
                     if(typeof(retmsg.data) != 'undefined' && typeof(retmsg.data.captcha) != 'undefined' && retmsg.data.captcha) {
                         $("#logincaptcha #captcha_code").prop("disabled", false); 
                         $("#logincaptcha").fadeIn('fast', function() {
                             if($("#logincaptcha #captcha_code").addClass("required").val().length > 0)
                            	 $("#logincaptcha #captcha_reload").trigger("click");
                         });
                     }
                     else if(!/captcha_code/.test(retmsg.error)) {
                         if($("#logincaptcha").css("display") != "none")
                             $("#logincaptcha #captcha_reload").trigger("click");
                     }
                 }
                 if(retmsg.success) {
                     window.location = retmsg.redirect; 
                  }
              } catch(e) {
                 return false;
              }
            }
         });
      
         return false;
      }
  });

  // focus first text-field 
  setFocus("jobseekerloginform");
  $("#jobseekerloginform .email").jobUtil("emailProvider");

}); 
